﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Linq;
using System.Text;
using GS.Config;
using System.Data.SqlClient;
using GS.CMS.Entities;

namespace GS.ManagerPage
{
    public class EntitesClass: System.Web.UI.Page
    {
        public Users _Users = new Users();
        protected System.Globalization.CultureInfo culture;
        protected override void InitializeCulture()
        {
            string lang = string.Empty;
            if (Request.Cookies["DefaultLang"] != null)
                lang = Request.Cookies["DefaultLang"].Value;
            else
            {
                if (Session["lang"] != null)
                    lang = Session["lang"].ToString();
                else
                    lang = "vi-VN";
            }
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
            base.InitializeCulture();
        }
        protected override void OnInit(EventArgs e)
        {
            GetUserInfo();
            //If error
            //this.Error += new EventHandler(Load_Error);
        }
        void Load_Error(object sender, EventArgs e)
        {
            //Exception ex = Server.GetLastError();

            //// Resolve the error page based on the exception that occurred
            //// and redirect to the appropriate page
            //if (ex is NotImplementedException)
            //    Server.Transfer(string.Format("errors/systemerrors.aspx", Config.Config.AdminError));
            //if (ex is FormatException)
            //    Server.Transfer(string.Format("errors/systemerrors.aspx", Config.Config.AdminError));
            //Server.Transfer(string.Format("errors/systemerrors.aspx", Config.Config.AdminError));
            //// Clear the error
            //Server.ClearError();

        }
        //int Logout()
        //{
        //    //System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    //ht.Add("@CookieID", ckCookieID);
        //    //return sqlProvider.ExecuteSQL("w_users_logout", ht);
        //}
        private void GetUserInfo()
        {
            DataTable dtUser = null;
            if (Session["UserInfo"] != null)
            {
                dtUser = (DataTable)Session["UserInfo"];
                //Get value to paras
                _Users.RoleID = (int)dtUser.Rows[0]["UserID"];
                _Users.Email = (string)dtUser.Rows[0]["Email"];
                _Users.AccountName = (string)dtUser.Rows[0]["AccountName"];
                _Users.FirstName = (string)dtUser.Rows[0]["FirstName"];
                _Users.LastName = (string)dtUser.Rows[0]["LastName"];
                _Users.RoleName = (string)dtUser.Rows[0]["RoleName"];
                _Users.Picture = (string)dtUser.Rows[0]["Picture"];
                _Users.GroupName = (string)dtUser.Rows[0]["GroupName"];
                _Users.ACLs = (string)dtUser.Rows[0]["ACLs"];
            }
        }
        //#region "write link"
        //public string WriteLink(string FileName, string Parameters, string linkText)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a href=\"{0}?ck={1}\">{2}</a>", FileName, ckCookieID, linkText);
        //    else
        //    {
        //        return string.Format("<a href=\"{0}?{1}&ck={2}\">{3}</a>", FileName, Parameters, ckCookieID, linkText);
        //    }
        //}
        //public string WriteLink(string FileName, string Parameters, string Class, string linkText)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a href=\"{0}?ck={1}\" class=\"{3}\" >{2}</a>", FileName, ckCookieID, linkText, Class);
        //    else
        //    {
        //        return string.Format("<a href=\"{0}?{1}&ck={2}\" class=\"{4}\" >{3}</a>", FileName, Parameters, ckCookieID, linkText, Class);
        //    }
        //}
        //public string WriteLink(string FileName, string Parameters, string Class, string linkText, string FunctionName)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a onclick=\"{4}\" href=\"{0}?ck={1}\" class=\"{3}\" >{2}</a>", FileName, ckCookieID, linkText, Class, FunctionName);
        //    else
        //    {
        //        return string.Format("<a onclick=\"{5}\" href=\"{0}?{1}&ck={2}\" class=\"{4}\" >{3}</a>", FileName, Parameters, ckCookieID, linkText, Class, FunctionName);
        //    }
        //}
        //#endregion

        //#region "write image"
        public string WriteImage(string ImageName, string Alt)
        {
            return string.Format("<img src=\"{0}\" alt=\"{1}\" />", ImageName, Alt);
        }
        //public string WriteImage(string ImageName, string Alt, string Class)
        //{
        //    return string.Format("<img class=\"{2}\" src=\"{0}\" alt=\"{1}\" />", ImageName, Alt, Class);
        //}
        //public string WriteImage(string ImageName, string Alt, int Width, int Height)
        //{
        //    return string.Format("<img src=\"{0}\" alt=\"{1}\" style=\"border:solid 1px #35A0D8;\" height=\"{3}px\" />", ImageName, Alt, Width, Height);
        //}
        //public string WriteImage(string ImageName, string Alt, string Border, int Width, int Height)
        //{
        //    return string.Format("<img src=\"{0}\" alt=\"{1}\" style=\"border:solid 1px {2};\" width=\"{3}px\" height=\"{4}px\" />", ImageName, Alt, Border, Width, Height);
        //}
        //public string WriteImage(string ImageName, string Alt, int Height)
        //{
        //    return string.Format("<img src=\"{0}\" alt=\"{1}\" height=\"{2}px\" vspace=\"5\" />", ImageName, Alt, Height);
        //}
        //public string WriteYMImage(string NickName)
        //{
        //    return string.Format("<a href=\"ymsgr:sendIM?{0}\"><img src=\"http://opi.yahoo.com/online?u={0}&m=g&t=14\"  /></a>", NickName);
        //}
        ////public string WriteIconSupport(Byte TypeSupport)
        ////{
        ////    if (TypeSupport == 1)
        ////        return string.Format("<img src=\"{0}YM.jpg\" alt=\"\" />", Config.Config.AdminIcon16, TypeSupport);
        ////    else
        ////        return string.Format("<img src=\"{0}Skype.jpg\" alt=\"\" />", Config.Config.AdminIcon16, TypeSupport);
        ////}
        //public string WriteImageActive(string ImageName, string Alt, string Function)
        //{
        //    return string.Format("<img src=\"{0}\" onclick=\"{2}\" alt=\"{1}\" title=\"{1}\" />", ImageName, Alt, Function);
        //}
        //#endregion

        //#region "write image link"
        //public string WriteImageLinkJS(string FileName, string Parameters, string ImageName, string Alt, string onClickedFunction)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a href=\"{0}?ck={1}\" onclick=\"return {4}\" ><img src=\"{2}\" alt=\"{3}\" title=\"{3}\" /></a>", FileName, ckCookieID, ImageName, Alt, onClickedFunction);
        //    else
        //    {
        //        return string.Format("<a href=\"{0}?{1}&ck={2}\" onclick=\"return {5}\"><img src=\"{3}\" alt=\"{4}\" title=\"{4}\" /></a>", FileName, Parameters, ckCookieID, ImageName, Alt, onClickedFunction);
        //    }
        //}
        public string WriteImageLink(string FileName, string Parameters, string ImageName, string Alt)
        {
            if (Parameters == string.Empty)
                return string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{2}\" /></a>", FileName, ImageName, Alt);
            else
            {
                return string.Format("<a href=\"{0}?{1}\"><img src=\"{2}\" alt=\"{3}\" /></a>", FileName, Parameters, ImageName, Alt);
            }
        }
        //public string WriteImageLink(string FileName, string Parameters, string ImageName, string Alt, string Class)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a href=\"{0}?ck={1}\"><img class=\"{4}\" src=\"{2}\" alt=\"{3}\" title=\"{3}\" /></a>", FileName, ckCookieID, ImageName, Alt, Class);
        //    else
        //    {
        //        return string.Format("<a href=\"{0}?{1}&ck={2}\"><img class=\"{5}\" src=\"{3}\" alt=\"{4}\" title=\"{4}\" /></a>", FileName, Parameters, ckCookieID, ImageName, Alt, Class);
        //    }
        //}
        //public string WriteImageLink(string FileName, string Parameters, string ImageName, string Alt, int Width)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a href=\"{0}?ck={1}\"><img src=\"{2}\" alt=\"{3}\" width=\"{4}\" /></a>", FileName, ckCookieID, ImageName, Alt, Width);
        //    else
        //    {
        //        return string.Format("<a href=\"{0}?{1}&ck={2}\"><img src=\"{3}\" alt=\"{4}\" width=\"{4}\" /></a>", FileName, Parameters, ckCookieID, ImageName, Alt, Width);
        //    }
        //}
        //public string WriteImageLink(string FileName, string Parameters, string ImageName, string Alt, int Width, int Height, string Class)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("<a href=\"{0}?ck={1}\" rel=\"lightbox[gallery]\"><img src=\"{2}\"  alt=\"{3}\" width=\"{5}\" vspace=\"5\" height=\"{4}\" class=\"{6}\"/></a>", FileName, ckCookieID, ImageName, Alt, Height, Width, Class);
        //    else
        //    {
        //        return string.Format("<a href=\"{0}?{1}&ck={2}\" rel=\"lightbox[gallery]\"><img src=\"{3}\"  alt=\"{4}\" width=\"{5}\" height=\"{6}\" class=\"{7}\" /></a>", FileName, Parameters, ckCookieID, ImageName, Alt, Width, Height, Class);
        //    }
        //}
        //#endregion

        //#region "write button"
        ////public string WriteEditButton(string EditPage, string EditParameters)
        ////{
        ////    return WriteImageLink(EditPage, EditParameters, string.Format("{0}ico_edit.gif", Config.Config.AdminIcon16), "Edit");
        ////}
        ////public string WriteActiveButton(string ActivatePage, string ActiveParameters, bool IsActive, string Function)
        ////{
        ////    if (IsActive)
        ////        return WriteImageActive(string.Format("{0}icon_02.jpg", Config.Config.AdminIcon16), "Bỏ kích hoạt", Function);
        ////    else
        ////        return WriteImageActive(string.Format("{0}icon_03.jpg", Config.Config.AdminIcon16), "Kích hoạt", Function);
        ////}
        ////public string WriteDeleteButton(string DeletePage, string DeleteParameters)
        ////{
        ////    return WriteImageLinkJS(DeletePage, DeleteParameters, string.Format("{0}icon_delete.png", Config.Config.AdminIcon16), "Delete", "removeConfirm()");
        ////}
        //#endregion

        //#region "other"
        //public string WriteURL(string FileName, string Parameters)
        //{
        //    if (Parameters == string.Empty)
        //        return string.Format("{0}?ck={1}", FileName, ckCookieID);
        //    else
        //    {
        //        return string.Format("{0}?{1}&ck={2}", FileName, Parameters, ckCookieID);
        //    }
        //}
        //public string WriteCheckbox(string Checkboxname, object Value)
        //{
        //    return string.Format("<input type=\"checkbox\" name=\"{0}\" value=\"{1}\" />", Checkboxname, Value);
        //}
        //public string WriteOption(string radioname, object Value)
        //{
        //    return string.Format("<input type=\"radio\" name=\"{0}\" value=\"{1}\" />", radioname, Value);
        //}
        //#endregion
    }
}
